{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 02 Valid discrete probability distribution examples" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "from pandas import Series, DataFrame\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[khanacademy](https://www.khanacademy.org/math/ap-statistics/random-variables-ap/discrete-random-variables/v/valid-discrete-probability-distribution-examples?modal=1)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![Valid discrete probability distribution examples fig 1](./imgs/09-02-01.png)![Valid discrete probability distribution examples fig 2](./imgs/09-02-02.png)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "basketball_df = DataFrame({'Outcome': ['Miss both free throws', 'Make exactly one free throw', 'Make both free throws'],\n", " 'Probabilty': [0.2, 0.5, 0.1]}).set_index('Outcome')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Probabilty
Outcome
Miss both free throws0.2
Make exactly one free throw0.5
Make both free throws0.1
\n", "
" ], "text/plain": [ " Probabilty\n", "Outcome \n", "Miss both free throws 0.2\n", "Make exactly one free throw 0.5\n", "Make both free throws 0.1" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "basketball_df" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "basketball_df['Probabilty'].sum() == 1" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "creatures_df = DataFrame({'Type of Earth Creature': ['Chickens', 'Cows', 'Humans'], '#': [97, 47, 77]}).set_index('Type of Earth Creature')" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
#
Type of Earth Creature
Chickens97
Cows47
Humans77
\n", "
" ], "text/plain": [ " #\n", "Type of Earth Creature \n", "Chickens 97\n", "Cows 47\n", "Humans 77" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "creatures_df" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "creatures_df['Estimated Probabilty'] = creatures_df['#'] / creatures_df['#'].sum()" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "creatures_df = creatures_df[['Estimated Probabilty']]" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Estimated Probabilty
Type of Earth Creature
Chickens0.438914
Cows0.212670
Humans0.348416
\n", "
" ], "text/plain": [ " Estimated Probabilty\n", "Type of Earth Creature \n", "Chickens 0.438914\n", "Cows 0.212670\n", "Humans 0.348416" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "creatures_df" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "creatures_df['Estimated Probabilty'].sum() == 1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 4 }